//
//  QuanziDetailViewController.m
//  YiqiMobile
//
//  Created by henry on 13-4-6.
//  Copyright (c) 2013年 henry. All rights reserved.
//

#import "QuanziDetailViewController.h"
#import "QuanziDetailCell.h"
#import "Utility.h"
#import "Config.h"

@interface QuanziDetailViewController ()
-(void) addsubActon:(UIButton*) sender;
-(UIView *) tableviewHeader;
@end

@implementation QuanziDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.titleView=[Utility getTitleView:@"详细资料"];
    float height=363;
    if (iPhone5) {
        height=451;
    }
    self.mytableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, height)];
    self.mytableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    self.mytableView.dataSource=self;
    self.mytableView.delegate=self;
    [self.view addSubview:self.mytableView];
    
    UIView *bottumView=[[UIView alloc] initWithFrame:CGRectMake(0, self.mytableView.frame.size.height, self.view.frame.size.width, 53)];
    bottumView.backgroundColor=[UIColor colorWithPatternImage:[Utility imageNamed:@"bottumView_bg.png"]];
    [self.view addSubview:bottumView];
    
    [bottumView addSubview:[Utility customButton:self action:@selector(addsubActon:) normalImage:@"quanzi_liuyan_normal.png" lightedImage:@"quanzi_liuyan_hover.png"  frame:CGRectMake(12, 13, 91, 28) title:nil tag:QUANZIDETAILBUTTONTAG]];
    [bottumView addSubview:[Utility customButton:self action:@selector(addsubActon:) normalImage:@"quanzi_yuyin_normal.png" lightedImage:@"quanzi_yuyin_hover.png"  frame:CGRectMake(115, 13, 91, 28) title:nil tag:QUANZIDETAILBUTTONTAG+1]];
    [bottumView addSubview:[Utility customButton:self action:@selector(addsubActon:) normalImage:@"quanzi_share_normal.png" lightedImage:@"quanzi_share_hover.png"  frame:CGRectMake(217, 13, 91, 28) title:nil tag:QUANZIDETAILBUTTONTAG+2]];
    self.arrayList=[NSMutableArray array];
    [self.arrayList addObject:@"国际在线消息："];
    [self.arrayList addObject:@"国际在线消息：据外交部网站消息，对于越南外交部称中国船只在西沙海域向越南渔船开枪射击一事，中国外交部发言人洪磊在26日的例行记者会上表示，越南渔船进入中国西沙海域进行非法作业，中方采取行动是必要的、正当的外交部发言人洪磊在26日的例行记者会上表示，越南渔船进入中国西沙海域进行非法作业，中方采取行动是必要的、正当的"];
    [self.arrayList addObject:@"国际在线消息：据外交部网站消息，对于越南外交部称中国船只在西沙海域向"];
    [self.arrayList addObject:@"国际在线消息：据外交部网站消息，对于越南外交部称中国船只在西沙海域向越"];
    for (int i=0;i<10;i++) {
        [self.arrayList addObject:@"国际在线消息：据外交部网站消息，对于越南外交部称中国船只在西沙海域向越南渔船开枪射击一事，中国外交部发言人洪磊在26日的例行记者会上表示，越南渔船进入中国西沙海域进行非法作业，中方采取行动是必要的、正当的"];
    }
    [self.mytableView reloadData];
	// Do any additional setup after loading the view.
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.arrayList count]+1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentity = @"quanziDetailCell";
     static NSString *cellIdentity0 = @"quanziDetailCell0";
    QuanziDetailCell *cell;
    if (indexPath.row==0) {
        cell = (QuanziDetailCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentity0];
        if (cell ==  nil) {
            cell = (QuanziDetailCell*)[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentity0];
             cell.selectionStyle=UITableViewCellSelectionStyleNone;
            UIView *header=[self tableviewHeader];
            cell.frame=header.frame;
            [cell addSubview:header];
        }
   
    }else{
            cell = (QuanziDetailCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentity];
            if (cell ==  nil) {
                cell = [[QuanziDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentity];
            }
            
            NSString *content=[self.arrayList objectAtIndex:indexPath.row-1];
            UIFont *font=[UIFont fontWithName:FONT_FAMILY size:15.0f];
            CGSize size=[Utility getStringSize:content font:font withMaxSize:CGSizeMake(290, 100)];
            if ((indexPath.row) %2==0) {
                cell.frame=CGRectMake(0, 0, 320, size.height+50);
                cell.content.hidden=NO;
                cell.yuyinButton.hidden=YES;
                cell.content.frame=CGRectMake(65, 35, 254, size.height);
                cell.content.numberOfLines=size.height/20;
                cell.content.text=content;


            }else{//图片85*58
                cell.frame=CGRectMake(0, 35, 320, 73);
                cell.content.hidden=YES;
                cell.yuyinButton.frame=CGRectMake(60, 35, 73, 33);
                cell.yuyinButton.hidden=NO;
                
            }
            cell.logo.frame=CGRectMake(15, (cell.frame.size.height-30)/2, 30, 30);
            cell.logo.image=[Utility imageNamed:@"pesonalLogo.png"];
             cell.detalContent.frame=CGRectMake(66, 20, 240, 14);
            cell.detalContent.text=[NSString stringWithFormat:@"%@  %@供稿  阅读:%@",@"2013-1-23",@"Apple",@"156"];
    }
    return cell;
}

-(void) addsubActon:(UIButton*) sender{
    switch (sender.tag-QUANZIDETAILBUTTONTAG) {
        case 0:{
            NSLog(@"%@",@"留言");
            break;
        }
        case 1:{
            NSLog(@"%@",@"语音");
            break;
        }
        case 2:{
            NSLog(@"%@",@"分享");
            break;
        }
        default:
            break;
    }
   
}

-(UIView *) tableviewHeader{
    NSString *content=@"关于朝鲜宣布暂时关闭开城工业园，中方认为，朝韩双方改善关系、和解合作有利于半岛和平稳定。当前朝鲜半岛形势复杂敏感";
    UIFont *font=[UIFont fontWithName:FONT_FAMILY size:12.0f];
    CGSize size=[Utility getStringSize:content font:font withMaxSize:CGSizeMake(296, 100)];
    UIView *header=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 180+size.height)];
    //圈子名称
    UILabel *labelleft1=[Utility detailTextLabel:CGRectMake(12, 12, 58, 20) andFontSize:15.0f];
    labelleft1.textColor=UIColorFromRGB(0x717171);
    labelleft1.text=@"圈子名称:";
    UILabel *labelright1=[Utility detailTextLabel:CGRectMake(70, 12, 280, 20) andFontSize:15.0f];
    labelright1.textColor=UIColorFromRGB(0x000000);
    labelright1.text=@"圈子名称";
    [header  addSubview:labelleft1];
    [header addSubview:labelright1];
    
     //圈子介绍
     UILabel *labell2=[Utility detailTextLabel:CGRectMake(12, 40, 88, 20) andFontSize:15.0f];
    labell2.textColor=UIColorFromRGB(0x717171);
    labell2.text=@"详细介绍:";
    UILabel *labellDetail2=[Utility detailTextLabel:CGRectMake(12, 66, 296, size.height) andFontSize:12.0f];
    labellDetail2.textColor=UIColorFromRGB(0x000000);
    labellDetail2.text=content;
    labellDetail2.numberOfLines=size.height/17.0;
    [header  addSubview:labell2];
    [header addSubview:labellDetail2];
    
    //圈子联系方式
    UILabel *labelleft2=[Utility detailTextLabel:CGRectMake(12, labellDetail2.frame.origin.y+size.height+10, 58, 17) andFontSize:12.0f];
    labelleft2.textColor=UIColorFromRGB(0x717171);
    labelleft2.text=@"联系方式:";
    UILabel *labelright2=[Utility detailTextLabel:CGRectMake(70, labellDetail2.frame.origin.y+size.height+10, 280, 17) andFontSize:12.0f];
    labelright2.textColor=UIColorFromRGB(0x000000);
    labelright2.text=@"joywxz@126.com";
    [header  addSubview:labelleft2];
    [header addSubview:labelright2];
    
    //地址
    UILabel *labelleft3=[Utility detailTextLabel:CGRectMake(12, labelleft2.frame.origin.y+labelleft2.frame.size.height+10, 58, 17) andFontSize:12.0f];
    labelleft3.textColor=UIColorFromRGB(0x717171);
    labelleft3.text=@"地址:";
    UILabel *labelright3=[Utility detailTextLabel:CGRectMake(70, labelleft2.frame.origin.y+labelleft2.frame.size.height+10, 280, 17) andFontSize:12.0f];
    labelright3.textColor=UIColorFromRGB(0x000000);
    labelright3.text=@"广州市番禺区";
    [header  addSubview:labelleft3];
    [header addSubview:labelright3];
    
    //网页链接
    //地址
    UILabel *labelleft4=[Utility detailTextLabel:CGRectMake(12, labelleft3.frame.origin.y+labelleft3.frame.size.height+10, 58, 17) andFontSize:12.0f];
    labelleft4.textColor=UIColorFromRGB(0x717171);
    labelleft4.text=@"网页链接:";
    UILabel *labelright4=[Utility detailTextLabel:CGRectMake(70, labelleft3.frame.origin.y+labelleft3.frame.size.height+10, 280, 17) andFontSize:12.0f];
    labelright4.textColor=UIColorFromRGB(0x000000);
    labelright4.text=@"www.126.com";
    [header  addSubview:labelleft4];
    [header addSubview:labelright4];
    
    //留言数
    UILabel *labelleft5=[Utility detailTextLabel:CGRectMake(12, labelleft4.frame.origin.y+labelleft4.frame.size.height+10, 58, 17) andFontSize:12.0f];
    labelleft5.textColor=UIColorFromRGB(0x717171);
    labelleft5.text=@"留言数:";
    UILabel *labelright5=[Utility detailTextLabel:CGRectMake(70, labelleft4.frame.origin.y+labelleft4.frame.size.height+10, 280, 17) andFontSize:12.0f];
    labelright5.textColor=UIColorFromRGB(0x000000);
    labelright5.text=@"8";
    [header  addSubview:labelleft5];
    [header addSubview:labelright5];
    
    return header;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
